<?php

if (!defined('TOBBIVM'))
	header('location:/template/notrepassing.php');
/**
 * This file is part of TobbiVMShop.
 *
 * TobbiVMShop is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * TobbiVMShop is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with TobbiVMShop.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * Class recalculates the price for using fee-based options
 * used by price.calcuelate.php
 *
 * @version    $Id$
 * @package    TobbiVM-Shop
 * @copyright  Copyright (C) 2012
 * @author     Norbert Gebert
 * @license    GPL3
 */
class optionsCalculate
{

	// @var string S_text Buffer for outputtext
	private $_text = '';

	/**
	 * Generate optionstext for cart/order...
	 * @param  string $productId   product-id
	 */
	public function getOptionsPostText($productId)
	{
		if ($productId <= 0)
			return '';

		db::getInstance()->where('product_id', $productId);
		$attribute_id = db::getInstance()->getOne('product', NULL, 'product_attribute_id');

		// Get all options for given attribute-id
		db::getInstance()->where('options_attribute_id', 
			$attribute_id['product_attribute_id']);
		db::getInstance()->orderBy('options_order', 'ASC');
		$optionsList = db::getInstance()->get('options');
	
		$this->_text = '';

		if (db::getInstance()->count >= 1)
		{
			foreach ($optionsList as $optionRow)
			{
				switch ($optionRow['options_art'])
				{
					case '1': // Textrow
						$this->_text .=
							'1|' . $optionRow['options_name'] . '|' .
							$_POST[$optionRow['options_id'] . '_'] . '| ;';
						break;
					case '2': // Textfield
						$this->_text .=
							'2|' . $optionRow['options_name'] . '|' .
							nl2br($_POST[$optionRow['options_id'] . '_']) . '| ;';
						break;
					case '3': // Drop-Down
						$this->_text .=
							'3|' . $optionRow['options_name'] . '|' .
							$_POST[$optionRow['options_id'] . '_'] . ';';
						break;
					case '4': // Option-List
						if (isset($_POST[$optionRow['options_id'] . '_']))
						{
							foreach ($_POST[$optionRow['options_id'] . '_'] as $value)
							{
								$this->_text .=
									'4|' . $optionRow['options_name'] . '|' .
									$value . ';';
							}
						}
						break;
				}
			}
		}
		return $this->_text;
	}

}

?>